<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Binary Integer Literals</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Utility">
<link rel="up" href="../utilities.html" title="Utilities">
<link rel="prev" href="../../BOOST_BASE_FROM_ME_idm1199.html" title="Macro BOOST_BASE_FROM_MEMBER_MAX_ARITY">
<link rel="next" href="../../BOOST_BINARY.html" title="Macro BOOST_BINARY">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../BOOST_BASE_FROM_ME_idm1199.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../BOOST_BINARY.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility.utilities.binary_integer_literals"></a><a name="sec:BOOST_BINARY"></a><a class="link" href="binary_integer_literals.html" title="Binary Integer Literals">Binary
      Integer Literals</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="binary_integer_literals.html#utility.utilities.binary_integer_literals.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="binary_integer_literals.html#utility.utilities.binary_integer_literals.example">Example</a></span></dt>
<dt><span class="section"><a href="binary_integer_literals.html#boost_binary.reference">Reference</a></span></dt>
<dt><span class="section"><a href="binary_integer_literals.html#utility.utilities.binary_integer_literals.acknowledgments">Acknowledgments</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.binary_integer_literals.introduction"></a><a class="link" href="binary_integer_literals.html#utility.utilities.binary_integer_literals.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<p>
          The macro <code class="computeroutput"><span class="identifier">BOOST_BINARY</span></code>
          is used for the representation of binary literals. It takes as an argument
          a binary number arranged as an arbitrary amount of 1s and 0s in groupings
          of length 1 to 8, with groups separated by spaces. The macro serves as
          a replacement for <a href="https://en.cppreference.com/w/cpp/language/integer_literal" target="_top">binary
          integer literals</a>, adopted in C++14.
        </p>
<p>
          The type of the literal yielded is determined by the same rules as those
          of <a href="https://en.cppreference.com/w/cpp/language/integer_literal" target="_top">hex
          and octal literals</a>. By implementation, this macro expands directly
          to an octal literal during preprocessing, so there is no overhead at runtime
          and the result is usable in any place that an octal literal would be.
        </p>
<p>
          In order to directly support binary literals with suffixes, additional
          macros of the form <code class="computeroutput"><span class="identifier">BOOST_BINARY_XXX</span></code>
          are also provided, where <code class="computeroutput"><span class="identifier">XXX</span></code>
          is a standard integer suffix in all capital letters.
        </p>
<p>
          In addition, LL and ULL suffixes may be used for representing <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>
          and <code class="computeroutput"><span class="keyword">unsigned</span> <span class="keyword">long</span>
          <span class="keyword">long</span></code> types in compilers which provide
          them as an extension.
        </p>
<p>
          The <code class="computeroutput"><span class="identifier">BOOST_BINARY</span></code> family
          of macros resides in the header <a href="../../../../../../boost/utility/binary.hpp" target="_top">&lt;boost/utility/binary.hpp&gt;</a>.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.binary_integer_literals.example"></a><a class="link" href="binary_integer_literals.html#utility.utilities.binary_integer_literals.example" title="Example">Example</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span> <span class="keyword">int</span> <span class="special">);</span>

<span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="special">);</span>

<span class="keyword">void</span> <span class="identifier">bar</span><span class="special">()</span>
<span class="special">{</span>
  <span class="keyword">int</span> <span class="identifier">value1</span> <span class="special">=</span> <span class="identifier">BOOST_BINARY</span><span class="special">(</span> <span class="number">100</span> <span class="number">111000</span> <span class="number">01</span> <span class="number">1</span> <span class="number">110</span> <span class="special">);</span>

  <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="identifier">value2</span> <span class="special">=</span> <span class="identifier">BOOST_BINARY_UL</span><span class="special">(</span> <span class="number">100</span> <span class="number">001</span> <span class="special">);</span> <span class="comment">// unsigned long</span>

  <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">value3</span> <span class="special">=</span> <span class="identifier">BOOST_BINARY_LL</span><span class="special">(</span> <span class="number">11</span> <span class="number">000</span> <span class="special">);</span> <span class="comment">// long long if supported</span>

  <a href="https://en.cppreference.com/w/cpp/error/assert" target="_top"><code class="computeroutput"><span class="identifier">assert</span></code></a><span class="special">(</span>    <span class="identifier">BOOST_BINARY</span><span class="special">(</span> <span class="number">10010</span> <span class="special">)</span>
          <span class="special">&amp;</span>  <span class="identifier">BOOST_BINARY</span><span class="special">(</span> <span class="number">11000</span> <span class="special">)</span>
          <span class="special">==</span> <span class="identifier">BOOST_BINARY</span><span class="special">(</span> <span class="number">10000</span> <span class="special">)</span>
        <span class="special">);</span>

  <span class="identifier">foo</span><span class="special">(</span> <span class="identifier">BOOST_BINARY</span><span class="special">(</span> <span class="number">1010</span> <span class="special">)</span> <span class="special">);</span> <span class="comment">// calls the first foo</span>

  <span class="identifier">foo</span><span class="special">(</span> <span class="identifier">BOOST_BINARY_LU</span><span class="special">(</span> <span class="number">1010</span> <span class="special">)</span> <span class="special">);</span> <span class="comment">// calls the second foo</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_binary.reference"></a>Reference</h4></div></div></div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="header.boost.utility.binary_hpp"></a>Header &lt;<a href="../../../../../../boost/utility/binary.hpp" target="_top">boost/utility/binary.hpp</a>&gt;</h5></div></div></div>
<pre class="synopsis">

<a class="link" href="../../BOOST_BINARY.html" title="Macro BOOST_BINARY">BOOST_BINARY</a>(bit_groupings)
<a class="link" href="../../BOOST_BINARY_U.html" title="Macro BOOST_BINARY_U">BOOST_BINARY_U</a>(bit_groupings)
<a class="link" href="../../BOOST_BINARY_L.html" title="Macro BOOST_BINARY_L">BOOST_BINARY_L</a>(bit_groupings)
<a class="link" href="../../BOOST_BINARY_UL.html" title="Macro BOOST_BINARY_UL">BOOST_BINARY_UL</a>(bit_groupings)
<a class="link" href="../../BOOST_BINARY_LU.html" title="Macro BOOST_BINARY_LU">BOOST_BINARY_LU</a>(bit_groupings)
<a class="link" href="../../BOOST_BINARY_LL.html" title="Macro BOOST_BINARY_LL">BOOST_BINARY_LL</a>(bit_groupings)
<a class="link" href="../../BOOST_BINARY_ULL.html" title="Macro BOOST_BINARY_ULL">BOOST_BINARY_ULL</a>(bit_groupings)
<a class="link" href="../../BOOST_BINARY_LLU.html" title="Macro BOOST_BINARY_LLU">BOOST_BINARY_LLU</a>(bit_groupings)
<a class="link" href="../../BOOST_SUFFIXED_BIN_idm1360.html" title="Macro BOOST_SUFFIXED_BINARY_LITERAL">BOOST_SUFFIXED_BINARY_LITERAL</a>(bit_groupings, suffix)
<a class="link" href="../../BOOST_SUFFIXED_BIN_idm1363.html" title="Macro BOOST_SUFFIXED_BINARY_LITERAL_D">BOOST_SUFFIXED_BINARY_LITERAL_D</a>(d, bit_groupings, suffix)
<a class="link" href="../../BOOST_BINARY_LITERAL_D.html" title="Macro BOOST_BINARY_LITERAL_D">BOOST_BINARY_LITERAL_D</a>(d, bit_groupings)</pre>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.binary_integer_literals.acknowledgments"></a><a class="link" href="binary_integer_literals.html#utility.utilities.binary_integer_literals.acknowledgments" title="Acknowledgments">Acknowledgments</a>
</h4></div></div></div>
<p>
          Contributed by Matt Calabrese.
        </p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001 Beman Dawes<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../BOOST_BASE_FROM_ME_idm1199.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../BOOST_BINARY.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
